package com.ruoyi.project.system.shopconfig.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.shopconfig.domain.ShopConfig;
import com.ruoyi.project.system.shopconfig.service.IShopConfigService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 配置信息设置Controller
 * 
 * @author f_baisi
 * @date 2020-06-18
 */
@Controller
@RequestMapping("/system/shopconfig")
public class ShopConfigController extends BaseController
{
    private String prefix = "system/shopconfig";

    @Autowired
    private IShopConfigService shopConfigService;

    @RequiresPermissions("system:shopconfig:view")
    @GetMapping()
    public String shopconfig()
    {
        return prefix + "/shopconfig";
    }

    @RequiresPermissions("system:shopconfig:view")
    @GetMapping("/home")
    public String shopconfig1(ModelMap map)
    {
        map.put("shopConfig",this.shopConfigService.findAll().get(0));
        return prefix + "/homeconfig";
    }

    /**
     * 查询配置信息设置列表
     */
    @RequiresPermissions("system:shopconfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopConfig shopConfig)
    {
        startPage();
        List<ShopConfig> list = shopConfigService.selectShopConfigList(shopConfig);
        return getDataTable(list);
    }

    /**
     * 导出配置信息设置列表
     */
    @RequiresPermissions("system:shopconfig:export")
    @Log(title = "配置信息设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopConfig shopConfig)
    {
        List<ShopConfig> list = shopConfigService.selectShopConfigList(shopConfig);
        ExcelUtil<ShopConfig> util = new ExcelUtil<ShopConfig>(ShopConfig.class);
        return util.exportExcel(list, "shopconfig");
    }

    /**
     * 新增配置信息设置
     */
    @GetMapping("/info")
    public String info(ModelMap map)
    {
        map.put("shopConfig",this.shopConfigService.findAll().get(0));
        return prefix + "/shopconfig";
    }

    @PostMapping("/update")
    @Transactional
    public String updateShopConfig(ShopConfig shopConfig){
        this.shopConfigService.updateShopConfig(shopConfig);
        return "redirect:/"+prefix+"/info";
    }

    @PostMapping("/updatehome")
    @Transactional
    public String updatehomeShopConfig(ShopConfig shopConfig){
        this.shopConfigService.updateShopConfig(shopConfig);
        return "redirect:/"+prefix+"/home";
    }

    /**
     * 新增保存配置信息设置
     */
    @RequiresPermissions("system:shopconfig:add")
    @Log(title = "配置信息设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopConfig shopConfig)
    {
        return toAjax(shopConfigService.insertShopConfig(shopConfig));
    }

    /**
     * 修改配置信息设置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ShopConfig shopConfig = shopConfigService.selectShopConfigById(id);
        mmap.put("shopConfig", shopConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存配置信息设置
     */
    @RequiresPermissions("system:shopconfig:edit")
    @Log(title = "配置信息设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopConfig shopConfig)
    {
        return toAjax(shopConfigService.updateShopConfig(shopConfig));
    }

    /**
     * 删除配置信息设置
     */
    @RequiresPermissions("system:shopconfig:remove")
    @Log(title = "配置信息设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopConfigService.deleteShopConfigByIds(ids));
    }
}
